﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TaobaoERP.BusinessAPI
{
    public class Class1
    {
//        protected void Page_Load(object sender, EventArgs e)
//{
//HttpRequest request = HttpContext.Current.Request;
////在软件应用中心跳转到ISV应用时的URL参数中取得,user_id、app_instance_id和token
//string aepUserId = request.Params["user_id"];
//string aepInstanceId = request.Params["app_instance_id"];
//string appId = request.Params["app_id"]; //软件注册时获得
//string token = request.Params["token"]; //每次点击生成不一样的token，并只有10秒钟有效
//string code = "6c0a91f01a5411dd8179bad18f04aace";//软件注册时获得
//System.DateTime timestamp = System.DateTime.Now;//时间获得当前系统时间

////sip_sign签名字段的生成，将CERT CODE和所有接口要传的参数进行组合，再将组装好的字符串进行md5加密后转成16进制后得到一个32位的密文
//string sipsign = code + "appId" + appId + "appInstanceId" + aepInstanceId + "sip_apinamealisoft.validateUser" + "sip_appkey" + appId + "sip_timestamp" + timestamp + "token" + token + "userId" + aepUserId;

//MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
//sipsign =BitConverter.ToString( md5.ComputeHash(Encoding.UTF8.GetBytes(sipsign))).Replace("-","");
////sip_sign生成END

////系统级参数拼装，包括sip_appkey、sip_apiname、sip_timestamp和sip_sign，sip_apiname是接口名这里举validateUser为例
//string SIPdate = "sip_appkey=" + appId + "&sip_apiname=alisoft.validateUser&sip_timestamp="+timestamp+"&sip_sign="+sipsign;
////接口级参数拼装
//string apidate="&userId="+aepUserId+"&appId="+appId+"&appInstanceId="+aepInstanceId+"&token="+token;

//ASCIIEncoding encoding = new ASCIIEncoding();
//byte[] postdata =encoding.GetBytes(SIPdate + apidate);//所有要传参数拼装
//// Prepare web request...
////目前阿里软件的服务集成平台（SIP）的接口测试地址是：http://sipdev.alisoft.com/sip/rest，生产环境地址是：http://sip.alisoft.com/sip/rest,
////这里使用测试接口先，到正式上线时需要做切换
//HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://sipdev.alisoft.com/sip/rest");
//myRequest.Method = "POST";
//myRequest.ContentType = "application/x-www-form-urlencoded";
//myRequest.ContentLength = postdata.Length;
//Stream newStream = myRequest.GetRequestStream();
//// Send the data.
//newStream.Write(postdata, 0, postdata.Length);
//newStream.Close();
//// Get response
//HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
//StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
//string content = reader.ReadToEnd();

////解析接口返回值，这里选用XML格式的解析，接口默认返回是XML格式
//XmlDocument xmlDoc = new XmlDocument();
//xmlDoc.LoadXml(content);
//XmlNode xn = xmlDoc.SelectSingleNode("String");
//XmlElement xe = (XmlElement)xn;
//string result = xe.InnerText;
//if ("1".Equals(result))
//{
////如果是使用者。。。。
//windowalert("使用者");
//}
//else if ("0".Equals(result))
//{
////如果是订阅者。。。。
//windowalert("订阅者");
//}
//}

//private void windowalert(string str)
//{
//HttpResponse Response = HttpContext.Current.Response;
//Response.Write("<script>alert('" + str + "');window.close(true);</script>");
//}

//    }
}
}
